package sd.czw.com.miemiegoushop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;

import java.util.List;

import sd.czw.com.miemiegoushop.R;
import sd.czw.com.miemiegoushop.data.GoodsModelk;

/**
 * Created by czw
 * desc 描述：
 * on 2017/9/25.
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private Context context;
    private int width;
    private List<GoodsModelk.ErrmsgBean> datas;

    public MyAdapter(Context context,int width,List<GoodsModelk.ErrmsgBean> datas) {
        this.context = context;
        this.width = width;
        this.datas = datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item,null));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setWidth(width);
        holder.textView.setText(datas.get(position).getGoods_name());
        Glide.with(context).load("http://miemiegou.com/"+datas.get(position).getGoods_img()).asBitmap().placeholder(R.mipmap.miemiegou).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        TextView textView;
        ImageView imageView;
        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tv);
            imageView = (ImageView) itemView.findViewById(R.id.iv);
        }
    }
}
